//Display_Canvas.java
import java.io.ByteArrayOutputStream;

import java.io.InputStream;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
 * @file DisplayCanvas.java
 * @author chenyu
 * @mail zemochen@gmail.com
 * @data 2014年4月22日 下午11:17:48
 * @description: 程序入口
 */
public class DisplayCanvas extends MIDlet {

	private Display display;

	private MainScreen ms;

	public DisplayCanvas() {
		// TODO Auto-generated constructor stub
		display = Display.getDisplay(this);
		ms = new MainScreen(display, this);
		display.setCurrent(ms);
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	public String read_UTF(String filename) {
		String strReturn = "";
		InputStream in = null;
		ByteArrayOutputStream baos = null;

		try {
			in = getClass().getResourceAsStream(filename);
			baos = new ByteArrayOutputStream();
			// 循环读取数据
			int ch;
			while ((ch = in.read()) != -1) {
				baos.write(ch);
			}
			in.close();
			strReturn = new String(baos.toByteArray(), "UTF-8");
			baos.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("filename: " + filename);
		} finally {
			in = null;
		}
		return strReturn;
	}

}
